<?php

declare(strict_types=1);

namespace Api\Service\v1\Work;

use App\CustHub\Service\OpenWorkService;
use Mine\Exception\NormalStatusException;
use function Hyperf\Collection\data_get;

class CorpTagApiService
{
    public function getList(array $params)
    {
        $service = make(OpenWorkService::class,[$params['corp_id']]);
        $tagId = data_get($params['tag_id'],[]);
        $groupId = data_get($params['group_id'],[]);
        return $service->getCorpTagList($tagId,$groupId);
    }

    public function addCorpTag(array $data)
    {
        $service = make(OpenWorkService::class,[$data['corp_id']]);
        $groupId = data_get($data,'group_id');
        $groupName = data_get($data,'group_name');
        $order = data_get($data,'order');
        $tag = data_get($data,'tag');
        $rst = $service->addCorpTag($tag,$groupId,$groupName,$order);
        if($rst === false){
            throw new NormalStatusException($service->errMsg);
        }
        return $rst;
    }

    public function editCorpTag(array $data)
    {
        $service = make(OpenWorkService::class,[$data['corp_id']]);
        $id = data_get($data,'id');
        $name = data_get($data,'name');
        $order = data_get($data,'order');
        $rst = $service->editCorpTag($id,$name,$order);
        if($rst === false){
            throw new NormalStatusException($service->errMsg);
        }
        return true;
    }

    public function delCorpTag(array $data)
    {
        $service = make(OpenWorkService::class,[$data['corp_id']]);
        $tagId = data_get($data,'tag_id',[]);
        $groupId = data_get($data,'group_id',[]);
        $rst = $service->delCorpTag($tagId,$groupId);
        if($rst === false){
            throw new NormalStatusException($service->errMsg);
        }
        return true;
    }
}